// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
import FastClick from "fastclick";
import router from "./router";
import App from "./App";
import axios from "axios";
import VueRouter from "vue-router";
import Vuex from "vuex";
import vueOption from "./assets/js/vue-option";
import "@/assets/plugins/api.js"; //引入api文件
import VueAxios from "vue-axios";
import login from "@/assets/js/devLogin.js";
import axiosConfig from "./assets/js/axios-config.js";
// import './assets/js/vconsole.min.js'
import VuePlugins from "@/assets/plugins/vux-plugins.js";
import store from "./vuex";
import H5BridgeApi from '@/assets/js/H5BridgeApi'
// //引入vant ui组件
import Vant from 'vant';
import 'vant/lib/index.css';

import VueHtml5Plus from 'vue-html5plus';
Vue.use(VueHtml5Plus);
Vue.use(Vant);

// Vue.use(VueRouter)
Vue.use(Vuex);
Vue.use(VueAxios, axios);
// Vue.prototype.$hybridApi=hybridApi;
FastClick.attach(document.body);

Vue.config.productionTip = false;

window.getUserInfoSuccess = (data) => { 

  // alert("getUserInfoSuccess Success" + data)

  
  //  axiosConfig(data);
  //   // console.log('axios',this.$axios)
  //   // console.log('login', res.ticket)
  //   console.log("登录成功保存的结果");
  //   console.log(data);
  //   store.dispatch("changeUserInfo", {
  //     attr: "userData",
  //     val: data
  //   }); //将登录的用户信息先存到store里
  //   console.log('a',store.state.userInfo)
  //    // alert(data.ticket);
  //      new Vue({
  //     router,
  //     store,
  //     render: h => h(App)
  //   }).$mount("#app-box");
  }

function newVue() {


  window.bridgeApi.getUserInfo((data)=>{

    axiosConfig(data);
    // console.log('axios',this.$axios)
    // console.log('login', res.ticket)
    console.log("登录成功保存的结果");
    console.log(data);
    store.dispatch("changeUserInfo", {
      attr: "userData",
      val: data
    }); //将登录的用户信息先存到store里
    console.log('a',store.state.userInfo)
     // alert(data.ticket);
       new Vue({
      router,
      store,
      render: h => h(App)
    }).$mount("#app-box");


  })
  login("814968", "123456").then(res => {
  // login("admin", "admin").then(res => {
    axiosConfig(res);
    store.dispatch("changeUserInfo", {
      attr: "userData",
      val: res
    }); //将登录的用户信息先存到store里
    console.log('a555',store.state.userInfo)

    
  new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount("#app-box");
   
  });

}
if (process.env.NODE_ENV === "development") {
  // run dev时执行
  newVue();
  setInterval(() => {
    let params = {
      ApiType: "AppsMenuController",
      Parameters: [
        {
          Value: ""
        }
      ],
      Method: "GetAppsByIds",
      Loading: false
    };
    Vue.prototype.$axios(params).then(res => {});
  }, 1000 * 50);
} else {

  newVue();
  //run build
  var u = navigator.userAgent;
  var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android终端
  var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  //根据配置来引入
  if (isAndroid) {
    //安卓
    // document.write('<script src="static/js/android/cordova.js"></script>');
  }
  document.addEventListener("deviceready", function() {
   
    setInterval(() => {
      let params = {
        ApiType: "AppsMenuController",
        Parameters: [
          {
            Value: ""
          }
        ],
        Method: "GetAppsByIds",
        Loading: false
      };
      Vue.prototype.$axios(params).then(res => {});
    }, 1000 * 60 * 10);
  });
}
